package cn.swufe.edu.stu.hw_tools.Cal;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;

import cn.swufe.edu.stu.hw_tools.R;

public class DeIndexActivity extends AppCompatActivity {
    private ArrayList<HashMap<String, String>> listItems;
    private SimpleAdapter listItemAdapter;
    private int index = 0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_de_index);

        ListView listView = findViewById(R.id.CC4Indexlist);
        initListView();
        listView.setAdapter(listItemAdapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent config = getIntent();
                switch (position){
                    case 0:
                        index = 1;
                        break;
                    case 1:
                        index = 2;
                        break;
                    case 2:
                        index = 3;
                        break;
                    case 3:
                        index = 4;
                        break;
                    case 4:
                        index = 5;
                        break;
                    case 5:
                        index = 6;
                        break;
                    case 6:
                        index = 7;
                        break;
                    case 7:
                        index = 8;
                        break;
                    case 8:
                        index = 9;
                        break;
                    case 9:
                        index = 10;
                        break;
                    case 10:
                        index = 11;
                        break;
                    case 11:
                        index = 12;
                        break;
                }
                config.putExtra("index",index);
                setResult(3,config);
                finish();
            }
        });


    }

    private void initListView() {
        listItems = new ArrayList<HashMap<String, String>>();
        for (int i = 1; i < 13; i++) {
            HashMap<String, String> map = new HashMap<String, String>();
            map.put("kind", "选择期数： " ); // 标题文字
            map.put("discribe", " " + i); // 详情描述
            listItems.add(map);
        }
        // 生成适配器的Item和动态数组对应的元素
        listItemAdapter = new SimpleAdapter(this, listItems, // listItems数据源
                R.layout.list_tem2, // ListItem的XML布局实现
                new String[] { "kind", "discribe" },
                new int[] { R.id.kind, R.id.discribe}
        );
    }

}